package com.luocj.brvah_srl.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.luocj.brvah_srl.R;
import com.luocj.brvah_srl.evnet.MyEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;


public class FragmentA extends BaseFragment {
    private String TAG = FragmentA.class.getSimpleName();
    private View inflate;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        inflate = inflater.inflate(R.layout.fragment_a, container, false);
        return inflate;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
//        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        inflate.findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MyEvent("hahahah"));
                if (onButtonClickListener != null) {
                    onButtonClickListener.onClick();
                }
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i(TAG, "onResume: " + "-------->a");
//        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        EventBus.getDefault().unregister(this);
        Log.i(TAG, "onDestroy: " + "------->>>aaa");
    }

    @Override
    protected void loadData() {
        Log.i(TAG, "loadData: " + "load ---------------------a");
    }

    @Override
    protected void onVisible() {
        super.onVisible();
    }

    @Override
    protected void onInVisible() {
    }

    public interface onButtonClickListener {
        void onClick();
    }

    private onButtonClickListener onButtonClickListener;

    public void setOnButtonClickListener(FragmentA.onButtonClickListener onButtonClickListener) {
        this.onButtonClickListener = onButtonClickListener;
    }
}
